<template>
	<section>
		<!--工具条-->
		<el-col  v-if='isShow'  :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">


				<el-form-item label="分销商" prop="useruuid" >
					<el-select v-model="filters.useruuid" filterable placeholder="请选择分销商" >
						<el-option value="0" label="全部">全部</el-option>
						<el-option
								v-for="item in users"
								:key="item.user.useruuid"
								:label="item.user.username"
								:value="item.user.useruuid">
						</el-option>
					</el-select>
				</el-form-item>
				<!--<el-form-item label="省份" prop="provinceuuid">-->
					<!--<el-select v-model="filters.provinceuuid" placeholder="请选择省份">-->
						<!--<el-option value="0" label="全部">全部</el-option>-->
						<!--<el-option-->
								<!--v-for="item in info"-->
								<!--:key="item.provinceuuid"-->
								<!--:label="item.provincename"-->
								<!--:value="item.provinceuuid">-->
						<!--</el-option>-->
					<!--</el-select>-->
				<!--</el-form-item>-->
				<!--<el-form-item label="业务类型" prop="busuuid"  >-->
					<!--<el-select v-model="filters.busuuid" placeholder="请选择业务类型">-->
						<!--<el-option value="0" label="全部">全部</el-option>-->
						<!--<el-option-->
								<!--v-for="item in bus"-->
								<!--:key="item.busuuid"-->
								<!--:label="item.busname"-->
								<!--:value="item.busuuid">-->
						<!--</el-option>-->
					<!--</el-select>-->
				<!--</el-form-item>-->

				<!--<el-form-item>-->
					<!--<el-input v-model="filters.facevalue" placeholder="面值"></el-input>-->
				<!--</el-form-item>-->
<!--				<el-form-item label="供货商" prop="useruuid">-->
<!--					<el-select v-model="filters.useruuid" placeholder="请选择供货商"  >-->
<!--						<el-option value="0" label="全部">全部</el-option>-->
<!--						<el-option-->
<!--								v-for="item in users"-->
<!--								:key="item.user.useruuid"-->
<!--								:label="item.user.username"-->
<!--								:value="item.user.useruuid">-->
<!--						</el-option>-->
<!--					</el-select>-->
<!--				</el-form-item>-->
                <el-form-item>
                    <el-date-picker type="date" placeholder="开始时间" clearable  format="yyyy-MM-dd HH:mm:ss"   v-model="filters.starttime" style="width: 100%;"></el-date-picker>
                </el-form-item>
                <el-form-item>
                    <el-date-picker type="date" placeholder="结束时间" clearable format="yyyy-MM-dd HH:mm:ss"   v-model="filters.endtime" style="width: 100%;"></el-date-picker>
                </el-form-item>
				<el-form-item>
					<el-button type="primary" v-if='isShow'  v-on:click="countProfit">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="profits" v-if='isShow'   show-summary  highlight-current-row v-loading="listLoading" max-height="620" style="width: 100%;">
			<el-table-column type="index" width="60">
			</el-table-column>
			<el-table-column prop="username" label="分销渠道"  >
			</el-table-column>
			<el-table-column prop="downfacevalue" label="分销金额"  >
			</el-table-column>
			<el-table-column prop="discountDown" label="分销面值"  >
			</el-table-column>
			<el-table-column prop="upname" label="供货金额"  >
			</el-table-column>
			<el-table-column prop="discountUp" label="供货供货面值"  >
			</el-table-column>
			<el-table-column prop="profit" label="利润" width="120" sortable>
			</el-table-column>
		</el-table>

		<!--工具条-->
			<el-pagination layout="total,sizes,prev, pager, next" @current-change="handleCurrentChange"
						   @size-change="handleSizeChange" :page-size="20" :total="total" >
			</el-pagination>
	</section>
</template>

<script>
	import util from '../../common/js/util'
	//import NProgress from 'nprogress'
	import {countDownProfit, findAllDownShopInfo, findAllUpShopInfo, findOpeProBusShop} from '../../api/api';
    import moment from 'moment';

	export default {
		data() {
			return {
				filters: {
					facevalue: '',
                    useruuid:'',
                    busuuid:'',
					downprouuid:'',
					starttime:moment().subtract('hour', 3).format('YYYY-MM-DD HH:mm:ss'),
					endtime: moment(new Date(),"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD') + " 23:59:59"
				},
				users: [],
                bus: [],
                info:[],
				total: 0,
                profits:[],
                start: 0,
                pageSize: 10,
				listLoading: false,
				isShow: JSON.parse(sessionStorage.getItem("user")).usertype === 2 ? true : false,
			}
		},
		methods: {
			findAllUpShopInfo:function () {
				let para = {
					page: this.page,
				};
				findAllUpShopInfo(para).then(datas => {
					let {message, code, data} = datas;
					if (code !== "0") {
						if (code === "37") {
							this.$router.push({path: '/login'});
						}
						this.$message({
							message: message,
							type: 'error'
						});
					} else {
						this.users = data;
					}
				}).catch(e =>{
					this.listLoading = false;
				});;
			},
			//性别显示转换
			formatSex: function (row, column) {
				return row.sex == 1 ? '男' : row.sex == 0 ? '女' : '未知';
			}, handleCurrentChange: function (val) {
                this.start = val ;
                this.countProfit();
            },
            handleSizeChange: function (val) {
                this.pageSize = val;
                this.countProfit();
            },
            countProfit() {
				let para = {
                    pageSize: this.pageSize,
                    start: this.start,
                    facevalue: this.filters.facevalue,
                    useruuid:this.filters.useruuid == "0" ? "": this.filters.useruuid, //JSON.parse(sessionStorage.getItem("user")).useruuid,
                    busuuid:this.filters.busuuid == "0" ? "" : this.filters.busuuid,
					downprouuid:this.filters.downprouuid == "0" ? "" : this.filters.downprouuid,
                    starttime:  this.filters.starttime == undefined || this.filters.starttime == ""  ? "" :  moment(this.filters.starttime,"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD HH:mm:ss') ,
                    endtime: this.filters.endtime == undefined || this.filters.endtime == "" ? "" : this.filters.endtime
				};
				this.listLoading = true;

                countDownProfit(para).then(datas => {
                        let {message, code, data} = datas;
                        if (code !== "0") {
                            this.$message({
                                message: message,
                                type: 'error'
                            });
                        } else if (data ) {

                            this.profits = data.result ;
                            this.total = data.totalCount ;
                        }
                        this.listLoading = false;
                });
			},findAllDownShopInfo: function () {
                let para = {useruuid: JSON.parse(sessionStorage.getItem("user")).useruuid};
                findAllDownShopInfo(para).then(datas => {
                    let {message, code, data} = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.users = data;
                    }
                });
            },findOpeProBusShop(){
                let para = {
                    test: ''
                };
                findOpeProBusShop(para).then(datas => {
                    let {message, code, data} = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.info = data.info;
                        this.bus = data.bus;
                    }
                });
			}
		},
		mounted() {
		    //this.findOpeProBusShop();
		    this.findAllDownShopInfo();
			this.countProfit();
		}
	}

</script>

<style scoped>

</style>
